package be.pluyckx.batteryprogress.activity.fragment.settings;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckedTextView;
import android.widget.TextView;

import be.pluyckx.batteryprogress.R;
import be.pluyckx.batteryprogress.application.BatteryProgressApplication;
import be.pluyckx.batteryprogress.application.Constants;

/**
 * Created by Philip on 22/08/13.
 *
 * A Fragment which holds settings for file storage.
 */
public class FileStoreSettingsFragment extends Fragment {
  private CheckedTextView mStoreLogs;
  private CheckedTextView mStoreHistory;
  private TextView mStoreDirectory;


  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_settings_files, container, false);

    mStoreLogs = (CheckedTextView) view.findViewById(R.id.ctv_store_logs);
    mStoreHistory = (CheckedTextView) view.findViewById(R.id.ctv_store_history);
    mStoreDirectory = (TextView) view.findViewById(R.id.tv_store_directory);

    mStoreDirectory.setText(mStoreDirectory.getText() + "\"" + BatteryProgressApplication.getDataDirectory().getAbsolutePath() + "\"");

    mStoreHistory.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        mStoreHistory.toggle();
      }
    });
    mStoreLogs.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        mStoreLogs.toggle();
      }
    });

    return view;
  }

  @Override
  public void onResume() {
    super.onResume();

    mStoreHistory.setChecked(Constants.getStoreHistory());
    mStoreLogs.setChecked(Constants.getStoreLogs());
  }

  @Override
  public void onPause() {
    Constants.setStoreHistory(mStoreHistory.isChecked());
    Constants.setStoreLogs(mStoreLogs.isChecked());

    Log.d("RTSettings", "Preferences stored");

    super.onPause();
  }
}
